module TalkShoe
  class TalkCast
    attr_reader :id, :name, :rss_url, :stream_url, :episodes
    
    def initialize(options)
      if options.is_a?(String)
        initialize_from_xml(options)
      elsif options.is_a?(Hash)
        initialize_from_hash(options) 
      else
        raise ArgumentError.new("Cannot create TalkShoe::TalkCast from #{options}")
      end
    end
    
    def initialize_from_xml(xml)
      raise 'not yet supported!'
    end
    
    def initialize_from_hash(hash)
      @id = hash[:id]
      @name = hash[:name]
      @rss_url = hash[:rss_url]
      @stream_url= hash[:stream_url]
      @episodes = []
      if hash[:episodes]
        hash[:episodes].each { |ep| add_episode(ep) } 
      end
      add_episode(hash[:episode])
    end
    
    def add_episode(ep)
      if ep.kind_of?(TalkShoe::Episode)
        @episodes << ep
      elsif !ep.nil?
        @episodes << TalkShoe::Episode.new(ep)
      end
    end
    
    private :initialize_from_xml, :initialize_from_hash
  end
end